﻿// Tierless
// Copyright © 2010 Alphora
// This file is licensed under a modified BSD-license (see tierless_license.txt).

using System.Collections.Generic;
using System.ServiceModel;
using System.Linq;

using Tierless.Framework.Data;
using Tierless.Framework.Entities;
using Tierless.Framework.EntityTypes;
using Tierless.Framework.ServiceContracts;
using Tierless.Framework.Server.Data;

namespace Tierless.Framework.Services
{
	/// <summary>
	/// Provides the service implementation for out-of-process access to the entity manager.
	/// </summary>
	[ServiceBehavior(Name = "EntityService", Namespace = "http://Tierless.Framework.ServiceContracts/2010/08")]
	public class EntityService : IEntityService
	{
		/// <summary>
		/// Initializes a new instance of the EntityService class.
		/// </summary>
		public EntityService()
		{
			_entityManager = new EntityManager();
		}
		
		private EntityManager _entityManager;
		
		/// <inheritdoc/>
		public List<EntitySet> Get(EntityRequests lookupSet)
		{
			return _entityManager.Get(lookupSet);
		}

		/// <inheritdoc/>
		public EntitySaveResult Save(List<EntitySet> entitySets)
		{
			return _entityManager.Save(entitySets);
		}

		/// <inheritdoc/>
		public EntityType[] Describe(string[] entityNames)
		{
			return (from en in entityNames select _entityManager.Describe(en)).ToArray();
		}
	}
}
